﻿using UnityEngine;
using System.Collections;

public class Door : MonoBehaviour {

    public GameObject player;
    public Button Action;
      
    public Texture NoAction;
    public Texture EnterAction;
    public Texture ExitAction;

  //  private Transform[] AllButtons;
	void Start ()
    {
      // AllButtons = Action.gameObject.transform.parent.gameObject.GetComponentsInChildren<Transform>();
        if (Action!=null)
            Action.ButtonClick += Action_ButtonClick;
	}

    void Action_ButtonClick()
    {
        if(Character.Hidden)
        {
            Character.Hidden = false;
        }
        else
        {
            Character.Hidden = true;     
          
        }
    }	

    private void SetActive()
    {
        //for(int i=0;i<AllButtons.Length;i++)
        //{
        //   // AllButtons.
        //}
    }
    public bool Contains()
    {
        if (player.transform.position.x  > this.gameObject.transform.position.x - 0.5f && player.transform.position.x < this.gameObject.transform.localScale.x + this.gameObject.transform.position.x - 0.5f)
        {
            return true;
        }
        return false;
    }
	
	void Update () 
    {
        if (!Character.Hidden)
        {
            if (Contains())
            {
                Action.gameObject.SetActive(true);
                Action.guiTexture.texture = EnterAction;
            }
            else
            {
                Action.gameObject.SetActive(false);
                Action.guiTexture.texture = NoAction;
            }
        }
        else
        {
            Action.gameObject.SetActive(true);
            Action.guiTexture.texture = ExitAction;
        }
	}
}
